<!--
    -  Copyright (c) 2018-2025, haohanwork.com All rights reserved.
  -->
<template>
    <div class="execution">
        <basic-container>
            <avue-crud ref="crud"
                       :page.sync="page"
                       :data="tableData"
                       :permission="permissionList"
                       :table-loading="tableLoading"
                       :option="tableOption"
                       @on-load="getList"
                       @search-change="searchChange"
                       @refresh-change="refreshChange">
              <template slot-scope="scope" slot="menu">
                <el-button type="text"
                           size="small"
                           plain
                           v-show="scope.row.returnStatus==='1' || scope.row.returnStatus==='2'"
                           @click="jumpToedit(scope.row)">编辑</el-button>
                <el-button type="text"
                           size="small"
                           plain
                           @click="jumpToDetail(scope.row)">详情</el-button>
                <el-button type="text"
                           size="small"
                           plain
                           v-show="scope.row.returnStatus==='1' || scope.row.returnStatus==='3'"
                           @click="returnOrder(scope.row)">退货审核</el-button>
                <el-button type="text"
                           size="small"
                           plain
                           v-show="scope.row.returnStatus==='3'"
                           @click="take(scope.row)">确认收货</el-button>
                <el-button type="text"
                           size="small"
                           plain
                           v-show="scope.row.returnStatus==='5'"
                           @click="audit(scope.row)">入库</el-button>
                <el-button type="text"
                           size="small"
                           plain
                           v-show="scope.row.returnStatus==='5' || scope.row.returnStatus==='6'"
                           @click="trefund(scope.row)">申请退款</el-button>
              </template>
                <template slot="menuRight">
                    <el-button type="primary" icon="el-icon-edit"  size="small" @click="jumpToAdd">新增退货单</el-button>
                </template>
            </avue-crud>
        </basic-container>
    </div>
</template>
<!-- 采购退货 -->
<script>
    import {
        filterForm
    } from "../../../util/util";
    import {
        fetchList,
        returnOrder,
        refund,
        auditPassReturnOrder
    } from '@/api/scm/order/return_order'
    import {
        tableOption
    } from '@/const/crud/scm/order/return_order'
    import router from "@/router/router"
    export default {
        name: 'sendBack',
        data() {
            return {
                tableData: [],
                page: {
                    total: 0, // 总页数
                    currentPage: 1, // 当前页数
                    pageSize: 20 // 每页显示多少条
                },
                tableLoading: false,
                tableOption: tableOption
            }
        },
        methods: {
            getList(page, params={returnType:0}) {
                this.tableLoading = true
                fetchList(Object.assign({
                    current: page.currentPage,
                    size: page.pageSize
                }, params)).then(response => {
                    this.tableData = response.data.data.records
                    this.page.total = response.data.data.total
                    this.tableLoading = false
                })
            },
            //是否通过
            returnOrder(row){
              let query = {
                res:JSON.stringify(row)
              };
              console.log(query);
              router.push({path: '/orderCon/slip_cheack',query:query})
            },
            /**
             * @title 数据更新
             * @param row 为当前的数据
             * @param index 为当前更新数据的行数
             * @param done 为表单关闭函数
             *
             **/
            handleUpdate: function (row, index, done) {
                putObj(row).then(data => {
                    this.tableData.splice(index, 1, Object.assign({}, row))
                    this.$message({
                        showClose: true,
                        message: '修改成功',
                        type: 'success'
                    })
                    done()
                    this.getList(this.page)
                })
            },
            /**
             * 搜索回调
             */
            searchChange(form, done) {
                this.getList(this.page, form);
                done();
            },
            /**
             * 刷新回调
             */
            refreshChange(info) {
    this.getList(this.page, this.filterForm(info.searchForm));
},
            /**
             * 页面跳转 手动新增
             */
            jumpToAdd(){
                this.$router.push({path: '/orderCon/slip_handleAdd'})
            },
          jumpToDetail(row) {
            let query = {
              res:JSON.stringify(row)
            };
            console.log(query);
            this.$router.push({path: '/orderCon/slip_detail',query:query})
          },
          //确认收货
          take(row){
            let query = {
              res:JSON.stringify(row)
            };
            this.$router.push({path: '/orderCon/slip_takeOver',query:query})
          },
          //入库
          audit(row){
            let query = {
              res:JSON.stringify(row)
            };
            this.$router.push({path: '/orderCon/slip_Warehousing',query:query})
            // auditPassReturnOrder(row).then(res => {
            //   if(res.data.code === 0){
            //     this.$message.success('入库成功');
            //     this.getList(this.page)
            //   }else{
            //     this.$message.warning('入库失败');
            //   }
            // })
          },
          // 订单退款
          trefund(row){
            let obj = {
              pmId: row.pmId, payableSn: row.returnSn, billType: '4'
            };
            refund(obj).then(res => {
                if(res.data.code === 0){
                    this.$message.success('申请退款成功');
                    this.getList(this.page)
                    let query = {
                      payableSn:row.returnSn
                    }
                    console.log(row.payableSn,row);
                    //this.$router.push({path: '../../funds/supplier',query:query})
                }else{
                    this.$message.warning('申请退款失败');
                }
            })
          },
          jumpToedit(row) {
            let query = {
              res:JSON.stringify(row)
            };
            this.$router.push({path: '/orderCon/slip_edit',query:query})
          },
        }
    }
</script>

<style lang="scss" scoped>
</style>
